package com.situ.feemanagement.controller;

import com.situ.feemanagement.pojo.entity.Order;
import com.situ.feemanagement.pojo.query.OrderQuery;
import com.situ.feemanagement.service.IOrderService;
import com.situ.feemanagement.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @GetMapping("/list")
    public Result list(OrderQuery orderQuery) {
        Map<String, Object> map = orderService.selectByPage(orderQuery);
        return Result.ok(map);
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        orderService.deleteById(id);
        return Result.ok("删除成功");
    }

    @DeleteMapping("/deleteAll/{ids}")
    public Result deleteAll(@PathVariable Integer[] ids) {
        orderService.deleteAll(ids);
        return Result.ok("删除成功");
    }

    @PostMapping("/add")
    public Result add(@RequestBody Order order) {
        orderService.add(order);
        return Result.ok("添加成功");
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Order order = orderService.selectById(id);
        return Result.ok(order);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Order order) {
        orderService.update(order);
        return Result.ok("更新成功");
    }
}
